package com.zivwu.library.dao.net;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;



public class NetworkType {
    /**
     * WIFI网络
     */
    public static final int NETTYPE_WIFI = 0x01;

    /**
     * WAP网络
     */
    public static final int NETTYPE_CMWAP = 0x02;
    /**
     * NET网络
     */
    public static final int NETTYPE_CMNET = 0x03;

    /**
     * 没有网络
     */
    public static final int NETTYPE_NO_INTENT = 0x00;


    public int getNetworkType(Context context) {
        int netType = NETTYPE_NO_INTENT;
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
        if (networkInfo == null) {
            return netType;
        }
        int nType = networkInfo.getType();
        if (nType == ConnectivityManager.TYPE_MOBILE) {
            String extraInfo = networkInfo.getExtraInfo();
            if (!extraInfo.isEmpty()) {
                if (extraInfo.toLowerCase().equals("cmnet")) {
                    netType = NETTYPE_CMNET;
                } else {
                    netType = NETTYPE_CMWAP;
                }
            }
        } else if (nType == ConnectivityManager.TYPE_WIFI) {
            netType = NETTYPE_WIFI;
        }
        return netType;
    }

}
